//index.js
//获取应用实例
import * as API from "../../utils/config.js"
const app = getApp()

//轮播图
Page({
  data: {
    imgUrls: [
      // 'http://mhfm8tel.cdndm5.com/22/21074/20170802203648_880x385.jpg',
      // 'http://css99tel.cdndm5.com/v201804091412/dm5/images/m_sushengzhanchong2.jpg',
      // 'http://mhfm7tel.cdndm5.com/34/33991/20180403111352_880x385_179.jpg',
      // 'http://mhfm4tel.cdndm5.com/22/21077/20180417222749_880x385_65.jpg'
    ],
    indicatorDots: false,
    autoplay: true,
    interval: 5000,
    duration: 1000
  },
  tap_ch: function (e) {
    if (this.data.open) {
      this.setData({
        open: false
      });
    } else {
      this.setData({
        open: true
      });
    }
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  onLoad: function () {
    this._initData(),
    this.yuanchuang(),
    this.qingnian(),
    this.shaonv(),
    this.shenmei()
  },
  _initData() {
    wx.request({
      url: API.swiper,
      // data: {
      //   "key": "3d0937e1138c64c188d858605df77e18"
      // },
      success: (res) => {
        this.setData({
          imgUrls: res.data.data
        })
      }
    })
  },
  leixing(){
    wx.request({
      url: API.category,
      data: {
        "key": API.key,
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          leixing: res.data.result
        })
        console.log(this.data.leixing)
      }
    })
  },
  yuanchuang(){
    wx.request({
      url: API.book,
      data:{
        "key": API.key,
        "type":"少年漫画"
      },
      success:(res)=>{
        // console.log(res)
        this.setData({
          manhua: res.data.result.bookList
        })
        console.log(this.data.manhua)
      }
    })
  },
  
  shaonv() {
    wx.request({
      url: API.book,
      data: {
        "key": API.key,
        "type": "少女漫画"
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          shaonv: res.data.result.bookList
        })
        console.log(this.data.manhua)
      }
    })
  },
  qingnian() {
    wx.request({
      url: API.book,
      data: {
        "key": API.key,
        "type": "青年漫画"
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          qingnian: res.data.result.bookList
        })
        console.log(this.data.manhua)
      }
    })
  },
  shenmei() {
    wx.request({
      url: API.book,
      data: {
        "key": API.key,
        "type": "耽美漫画"
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          shenmei: res.data.result.bookList
        })
        console.log(this.data.manhua)
      }
    })
  },
  toast() {
    wx.navigateTo({
      url: '../gengduo/gengduo'
    })
  },
  zhangjie: function (e) {
    console.log(e)
    wx.navigateTo({
      url: '../zhangjie/zhangjie?sb=' + e.currentTarget.dataset.name + "&gt=" + e.currentTarget.dataset.img + "&tp=" + e.currentTarget.dataset.type + "&ar=" + e.currentTarget.dataset.area
    })
  },
  sousuo() {
    wx.navigateTo({
      url: '../sousuo/sousuo'
    })
  },
})


